#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <sys/stat.h>

#include "syntax.h"
#include "io.h"
#include "mem_macros.h"
#include "mem_structures.h"
#include "mem_functions.h"
#include "gui.h"

int main(int argc, char **argv)
{
    POSITION p = 1;
    int ret;
    char status[50];
    buffer_t* buffer;
    chunk_t* chunk;
    sFile* sf;

    (void)gui_init(argc,argv);

    if(argc!=2)
    {
        printf("RTFC\n");
        return 1;
    }

    if(argc==2)
    {
        sf = statFile(argv[1]);
        if(sf==NULL)
        {
            printf("Error using file '%s'\n",argv[1]);
            return 1;
        }

        ret = readFile(sf);
        if(ret!=0)
        {
            DEBUG_FATAL("Could not read file");
        }
        buffer = sf->buffer;
        gui_update_text(buffer);
        snprintf(status,50,"Editing : %s",argv[1]);
        gui_update_status(status);
    }

    ewl_main();

    mem_delBuffer(buffer);

    return 0;
}
